% ctex-options.def: options for all ctex packages/classes
% vim:ft=tex

\RequirePackage{kvoptions}
\RequirePackage{etoolbox}

\SetupKeyvalOptions{family=CTEX@opt, prefix=CTEX@, setkeys=\kvsetkeys}

\def\CTEX@set@opt{\kvsetkeys{CTEX@opt}}

\DeclareStringOption[GBK]{encoding}
\DeclareVoidOption{GBK} {\CTEX@set@opt{encoding=GBK}}
\DeclareVoidOption{UTF8}{\CTEX@set@opt{encoding=UTF8}}

\DeclareStringOption[CJK]{engine}
\DeclareVoidOption{zhmCJK}{\CTEX@set@opt{engine=zhmCJK}}

\DeclareVoidOption{CCT}    {\PackageWarning{ctex}{Deprecated option `CCT'.}}
\DeclareVoidOption{CCTfont}{\PackageWarning{ctex}{Deprecated option `CCTfont'.}}

\DeclareStringOption[windows]{fontset}[windows]
\DeclareVoidOption{nofonts}   {\CTEX@set@opt{fontset=none}}
\DeclareVoidOption{winfonts}  {\CTEX@set@opt{fontset=windows}}
\DeclareVoidOption{adobefonts}{\CTEX@set@opt{fontset=adobe}}
\DeclareVoidOption{macfonts}  {\CTEX@set@opt{fontset=mac}}

\DeclareBoolOption[true]{zhmap}
\DeclareComplementaryOption{nozhmap}{zhmap}

\DeclareBoolOption[true]{punct}
\DeclareComplementaryOption{nopunct}{punct}

\DeclareBoolOption[true]{cap}
\DeclareComplementaryOption{nocap}{cap}

\DeclareBoolOption[true]{caption}
\DeclareComplementaryOption{nocaption}{caption}

\DeclareBoolOption[true]{indent}
\DeclareComplementaryOption{noindent}{indent}

\DeclareBoolOption{space}
\DeclareComplementaryOption{nospace}{space}

\DeclareBoolOption{fancyhdr}
\DeclareBoolOption{fntef}
\DeclareBoolOption{hyperref}
\DeclareBoolOption{CJKspace}

\newcounter{CTEX@sectiondepth}
\setcounter{CTEX@sectiondepth}{2}
\DeclareVoidOption{sub3section}{\setcounter{CTEX@sectiondepth}{3}}
\DeclareVoidOption{sub4section}{\setcounter{CTEX@sectiondepth}{4}}

\DeclareBoolOption{sfoursize}
\DeclareBoolOption{fivesize}

\ifdefined\CTEX@classtoload
  \DeclareVoidOption{c5size}{%
    \CTEX@set@opt{sfoursize=false,fivesize=true}%
    \PassOptionsToClass{10pt}{\CTEX@classtoload}}
  \DeclareVoidOption{cs4size}{%
    \CTEX@set@opt{sfoursize=true,fivesize=false}
    \PassOptionsToClass{12pt}{\CTEX@classtoload}}
  \DeclareVoidOption{10pt}{%
    \CTEX@set@opt{sfoursize=false,fivesize=false}%
    \PassOptionsToClass{\CurrentOption}{\CTEX@classtoload}}
  \DeclareVoidOption{11pt}{%
    \CTEX@set@opt{sfoursize=false,fivesize=false}%
    \PassOptionsToClass{\CurrentOption}{\CTEX@classtoload}}
  \DeclareVoidOption{12pt}{%
    \CTEX@set@opt{sfoursize=false,fivesize=false}%
    \PassOptionsToClass{\CurrentOption}{\CTEX@classtoload}}
  \DeclareDefaultOption{%
    \PassOptionsToClass{\CurrentOption}{\CTEX@classtoload}}
  \CTEX@set@opt{c5size}
\else
%  \CTEX@set@opt{caption=false}
  \DeclareVoidOption{c5size} {\CTEX@set@opt{sfoursize=false,fivesize=true}}
  \DeclareVoidOption{cs4size}{\CTEX@set@opt{sfoursize=true,fivesize=false}}
  \@ifclassloaded{beamer}{\CTEX@set@opt{indent=false}}{}
\fi

\InputIfFileExists{ctexopts.cfg}{}{}

\ProcessKeyvalOptions*

\ifdefined\CTEX@classtoload
  \LoadClass{\CTEX@classtoload}
\fi

\forcsvlist{\listadd\CTEX@encoding@list}{GBK,UTF8}
\forcsvlist{\listadd\CTEX@engine@list}{CJK,zhmCJK}

\xifinlist\CTEX@encoding\CTEX@encoding@list{}{%
  \PackageError{ctex}
    {The encoding `\CTEX@encoding' is not supported,\MessageBreak
     please check it over.\MessageBreak
     `GBK' is used as default encoding.}
    {You can only use `UTF8' or `GBK'.}
  \CTEX@set@opt{encoding=GBK}}

\xifinlist\CTEX@engine\CTEX@engine@list{}{%
  \PackageError{ctex}
    {The engine `\CTEX@engine' is not supported,\MessageBreak
     please check it over.\MessageBreak
     `CJK' is used as default engine.}
    {You can only use `CJK' or `zhmCJK'.}%
  \CTEX@set@opt{engine=CJK}}

\endinput
